package org.edu.modules.scheduleCommon.dto;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.metadata.BaseRowModel;
import lombok.Data;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.util.CellRangeAddress;
import com.alibaba.excel.event.WriteHandler;

import java.util.List;

/**
 * 考勤表数据模型
 */
@Data
public class AttendanceData extends BaseRowModel {

    // 第一行合并周一到周五（占5列）
    @ExcelProperty(value = "周一至周五", index = 0)
    private String weekHeader;

    // 第二行显示节次（第1节到第9节）
    @ExcelProperty(value = "第1节", index = 1)
    private String period1;
    @ExcelProperty(value = "第2节", index = 2)
    private String period2;
    @ExcelProperty(value = "第3节", index = 3)
    private String period3;
    @ExcelProperty(value = "第4节", index = 4)
    private String period4;
    @ExcelProperty(value = "第5节", index = 5)
    private String period5;
    @ExcelProperty(value = "第6节", index = 6)
    private String period6;
    @ExcelProperty(value = "第7节", index = 7)
    private String period7;
    @ExcelProperty(value = "第8节", index = 8)
    private String period8;
    @ExcelProperty(value = "第9节", index = 9)
    private String period9;

    /**
     * 自定义表头合并处理器
     */
    public static class HeaderMergeHandler implements WriteHandler {
        @Override
        public void sheet(int sheetNo, org.apache.poi.ss.usermodel.Sheet sheet) {
            // 合并第一行的周一到周五（A1:E1）
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4));

            // 设置第二行的节次（每列对应一天中的节次）
            Row row = sheet.getRow(1);
            for (int i = 1; i <= 9; i++) {
                Cell cell = row.getCell(i);
                if (cell != null) {
                    cell.setCellValue("第" + i + "节");
                }
            }
        }

        @Override
        public void row(int i, Row row) {

        }

        @Override
        public void cell(int i, Cell cell) {

        }
    }
}
